import pandas as pd
from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler

# 模拟客户数据
data = {
    '年龄': [25, 45, 32, 28, 51, 36, 42, 29, 35, 48],
    '年收入(万)': [15, 80, 25, 18, 120, 45, 75, 22, 38, 95],
    '消费频率': [3, 1, 4, 5, 1, 3, 2, 6, 4, 2]
}

df = pd.DataFrame(data)

# 数据标准化
scaler = StandardScaler()
scaled_data = scaler.fit_transform(df)

# 客户分群
kmeans = KMeans(n_clusters=3, random_state=42)
df['客户分群'] = kmeans.fit_predict(scaled_data)

# 分析不同客户群特征
cluster_summary = df.groupby('客户分群').mean()
print(cluster_summary)